package com.longge.wechat.controller.wx;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.longge.wechat.communication.Poster;
import com.longge.wechat.message.resp.Article;
import com.longge.wechat.message.resp.RespArticleMessage;
import com.longge.wechat.utils.XmlUtil;



@Controller
public class RespArticleController {


	@RequestMapping(value = "/article.do", method = RequestMethod.POST)
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Article article = new Article();
		article.setDescription("这是图文测试");
		article.setPicUrl("789");
		article.setTitle("图文测试");
		article.setUrl("575769");
		
		Article article2 = new Article();
		article2.setDescription("这是图文测试2");
		article2.setPicUrl("7892");
		article2.setTitle("图文测试2");
		article2.setUrl("5757692");
		
		List<Article> articles = new ArrayList<Article>();
		articles.add(article);
		articles.add(article2);
		
		RespArticleMessage message = new RespArticleMessage(
				(String) request.getAttribute("openId"),
				(String) request.getAttribute("from"));
		message.setArticles(articles);
		
		XmlUtil xmlUtil1 = XmlUtil.getInstance();
		String xml = xmlUtil1.bean2xml(message,null,null).replaceAll(
				"com.longge.wechat.message.resp.Article", "item");
		Poster.post(response, xml);
	}
}
